#coding=utf-8
#Boa:Dialog:DlgTableSale

import wx

from product import CDataTableSale

def create(parent):
    return DlgTableSale(parent)

[wxID_DLGTABLESALE, wxID_DLGTABLESALEBTNCANCEL, wxID_DLGTABLESALEBTNCONFIRM, 
 wxID_DLGTABLESALECBSAVEPAPER, wxID_DLGTABLESALECBSAVEPAPER2, 
 wxID_DLGTABLESALECHECKBUYER, wxID_DLGTABLESALECHECKDEBT, 
 wxID_DLGTABLESALECHECKPHONE, wxID_DLGTABLESALECOMBOPAPER, 
 wxID_DLGTABLESALESTATICTEXT1, wxID_DLGTABLESALETCFOOTER, 
 wxID_DLGTABLESALETCTITLE, wxID_DLGTABLESALETFOOTER, wxID_DLGTABLESALETTITLE, 
] = [wx.NewId() for _init_ctrls in range(14)]

class DlgTableSale(wx.Dialog):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Dialog.__init__(self, id=wxID_DLGTABLESALE, name=u'DlgTableSale',
              parent=prnt, pos=wx.Point(398, 191), size=wx.Size(832, 508),
              style=wx.DEFAULT_DIALOG_STYLE,
              title=u'\u6253\u5370\u62a5\u8868--\u9500\u552e\u5355')
        self.SetClientSize(wx.Size(824, 474))
        self.Center(wx.BOTH)
        self.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, u'Arial'))
        self.SetBackgroundColour(wx.Colour(183, 209, 173))

        self.tTitle = wx.StaticText(id=wxID_DLGTABLESALETTITLE,
              label=u'\u62a5\u8868\u6807\u9898\uff1a', name=u'tTitle',
              parent=self, pos=wx.Point(24, 16), size=wx.Size(85, 19), style=0)

        self.tFooter = wx.StaticText(id=wxID_DLGTABLESALETFOOTER,
              label=u'\u62a5\u8868\u9875\u811a\uff1a', name=u'tFooter',
              parent=self, pos=wx.Point(24, 72), size=wx.Size(96, 24), style=0)

        self.tcTitle = wx.TextCtrl(id=wxID_DLGTABLESALETCTITLE, name=u'tcTitle',
              parent=self, pos=wx.Point(16, 40), size=wx.Size(328, 24), style=0,
              value=u'')

        self.tcFooter = wx.TextCtrl(id=wxID_DLGTABLESALETCFOOTER,
              name=u'tcFooter', parent=self, pos=wx.Point(16, 96),
              size=wx.Size(792, 96), style=wx.TE_MULTILINE, value=u'')

        self.btnConfirm = wx.Button(id=wxID_DLGTABLESALEBTNCONFIRM,
              label=u'\u786e\u5b9a', name=u'btnConfirm', parent=self,
              pos=wx.Point(248, 368), size=wx.Size(88, 32), style=0)
        self.btnConfirm.Bind(wx.EVT_BUTTON, self.OnBtnConfirmButton,
              id=wxID_DLGTABLESALEBTNCONFIRM)

        self.btnCancel = wx.Button(id=wxID_DLGTABLESALEBTNCANCEL,
              label=u'\u53d6\u6d88', name=u'btnCancel', parent=self,
              pos=wx.Point(440, 368), size=wx.Size(88, 32), style=0)
        self.btnCancel.Bind(wx.EVT_BUTTON, self.OnBtnCancelButton,
              id=wxID_DLGTABLESALEBTNCANCEL)

        self.checkBuyer = wx.CheckBox(id=wxID_DLGTABLESALECHECKBUYER,
              label=u'\u662f\u5426\u6253\u5370\u91c7\u8d2d\u5458\u4fe1\u606f',
              name=u'checkBuyer', parent=self, pos=wx.Point(24, 248),
              size=wx.Size(200, 19), style=0)
        self.checkBuyer.SetValue(False)

        self.checkDebt = wx.CheckBox(id=wxID_DLGTABLESALECHECKDEBT,
              label=u'\u6709\u6b20\u6b3e\u65f6\uff0c\u6253\u5370\u6b20\u6b3e\u603b\u989d',
              name=u'checkDebt', parent=self, pos=wx.Point(24, 312),
              size=wx.Size(248, 19), style=0)
        self.checkDebt.SetValue(True)

        self.checkPhone = wx.CheckBox(id=wxID_DLGTABLESALECHECKPHONE,
              label=u'\u662f\u5426\u6253\u5370\u516c\u53f8\u7535\u8bdd',
              name=u'checkPhone', parent=self, pos=wx.Point(24, 280),
              size=wx.Size(216, 19), style=0)
        self.checkPhone.SetValue(True)

        self.cbSavePaper = wx.CheckBox(id=wxID_DLGTABLESALECBSAVEPAPER,
              label=u'\u8282\u7eb8\u6a21\u5f0f1\uff0c\u4e2d\u95f4\u9875\u4e0d\u6253\u5370\u9875\u5934\u9875\u811a',
              name=u'cbSavePaper', parent=self, pos=wx.Point(376, 248),
              size=wx.Size(320, 19), style=0)
        self.cbSavePaper.SetValue(False)
        self.cbSavePaper.Bind(wx.EVT_CHECKBOX, self.OnCbSavePaperCheckbox,
              id=wxID_DLGTABLESALECBSAVEPAPER)

        self.cbSavePaper2 = wx.CheckBox(id=wxID_DLGTABLESALECBSAVEPAPER2,
              label=u'\u8282\u7eb8\u6a21\u5f0f2\uff0c\u4e2d\u95f4\u9875\u6253\u5370\u9875\u5934\u4e0d\u6253\u5370\u9875\u811a',
              name=u'cbSavePaper2', parent=self, pos=wx.Point(376, 280),
              size=wx.Size(328, 19), style=0)
        self.cbSavePaper2.SetValue(True)
        self.cbSavePaper2.Bind(wx.EVT_CHECKBOX, self.OnCbSavePaper2Checkbox,
              id=wxID_DLGTABLESALECBSAVEPAPER2)

        self.staticText1 = wx.StaticText(id=wxID_DLGTABLESALESTATICTEXT1,
              label=u'\u7eb8\u5f20\u7c7b\u578b\uff1a', name='staticText1',
              parent=self, pos=wx.Point(24, 216), size=wx.Size(85, 19),
              style=0)

        self.comboPaper = wx.ComboBox(choices=[],
              id=wxID_DLGTABLESALECOMBOPAPER, name=u'comboPaper', parent=self,
              pos=wx.Point(112, 208), size=wx.Size(100, 27),
              style=wx.CB_READONLY, value=u'\u4e8c\u7b49\u5206')
        self.comboPaper.SetLabel(u'\u4e8c\u7b49\u5206')

    def __init__(self, parent):
        self._init_ctrls(parent)

        self.myInit()
        
    def myInit(self):
        self.tblSale = CDataTableSale.getTableSale()
        
        self.tcTitle.SetValue(self.tblSale.getValue(CDataTableSale.iTitle))
        self.tcFooter.SetValue(self.tblSale.getValue(CDataTableSale.iFooter))
        
        self.checkBuyer.SetValue(self.tblSale.getValue(CDataTableSale.iBuyer))
        self.checkDebt.SetValue(self.tblSale.getValue(CDataTableSale.iDebt))
        self.checkPhone.SetValue(self.tblSale.getValue(CDataTableSale.iPhone))
        
        if self.tblSale.getValue(CDataTableSale.iSavePaper) == 1:
            self.cbSavePaper.SetValue(True)
            self.cbSavePaper2.SetValue(False)
        elif self.tblSale.getValue(CDataTableSale.iSavePaper) == 2:
            self.cbSavePaper.SetValue(False)
            self.cbSavePaper2.SetValue(True)
        else:
            self.cbSavePaper.SetValue(False)
            self.cbSavePaper2.SetValue(False)  
            
        self.__init_comboPaper()

    def __init_comboPaper(self):
        self.paperSize = {1:u'一等分',2:u'二等分',3:u'三等分',4:u'四等分'}
        
        self.comboPaper.Clear()
        
        for key,val in self.paperSize.items():
            self.comboPaper.Append(val, key)
            
        self.comboPaper.SetValue(self.paperSize[self.tblSale.getValue(CDataTableSale.iPaperSize)])
            
                
    def OnBtnConfirmButton(self, event):
        title = self.tcTitle.GetValue()
        footer = self.tcFooter.GetValue()
        
        obj = CDataTableSale.getTableSale()
        
##        try:
##            obj.setValue(obj.iMaxDetailNum, int(self.tcCnt.GetValue()))
##        except:
##            dlg = wx.MessageDialog(self, u'请输入正整数', u'提示消息', wx.OK|wx.ICON_ERROR)
##            dlg.ShowModal()
##            return
            
        obj.setValue(obj.iSavePaper, 0)
        if self.cbSavePaper.IsChecked():
            obj.setValue(obj.iSavePaper, 1)
        elif self.cbSavePaper2.IsChecked():
            obj.setValue(obj.iSavePaper, 2)
        
        obj.setValue(obj.iPaperSize, self.comboPaper.GetClientData(self.comboPaper.GetSelection()))
        
        obj.setValue(obj.iTitle, title)
        obj.setValue(obj.iFooter, footer)
        obj.setValue(obj.iBuyer, self.checkBuyer.GetValue())
        obj.setValue(obj.iDebt, self.checkDebt.GetValue())
        obj.setValue(obj.iPhone, self.checkPhone.GetValue())
        
        obj.update()
        
        self.Close()

    def OnBtnCancelButton(self, event):
        self.Close()

    def OnCbSavePaperCheckbox(self, event):
        if self.cbSavePaper.IsChecked():
            self.cbSavePaper2.SetValue(0)
        else:
            self.cbSavePaper2.SetValue(1)

    def OnCbSavePaper2Checkbox(self, event):
        if self.cbSavePaper2.IsChecked():
            self.cbSavePaper.SetValue(0)
        else:
            self.cbSavePaper.SetValue(1)